﻿Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration

Public Class Connect
    Private stconnect As String = ConfigurationManager.AppSettings("stconnect").ToString
    Private conn As SqlConnection
    Private cmd As SqlCommand
    Public Function Connect() As Boolean
        conn = New SqlConnection(stconnect)
        Try
            conn.Open()

        Catch ex As Exception
            System.Windows.Forms.MessageBox.Show("Không thể kết nối tới Database !" + ex.Message)
        End Try
        Return True
    End Function
    Public Sub Close()
        If conn.State = ConnectionState.Open Then
            conn.Close()

        End If
        conn.Dispose()
    End Sub
    Public Function GetData(ByVal sSql As String) As DataTable
        Dim dt As New DataTable
        Connect()
        cmd = New SqlCommand(sSql, conn)
        Dim da As New SqlDataAdapter(cmd)
        da.Fill(dt)
        Close()
        Return dt
    End Function
End Class
